<template>
	<view>
		<view class="top-tab-view">
			<view class="left-tab">
				<!-- <view @click="selectedTab('推荐')" class="tab-item" :class="tabSelected==='推荐'? 'tab-selected':''">推荐</view>
				<view @click="selectedTab('最新')" class="tab-item" :class="tabSelected==='最新'? 'tab-selected':''">最新</view>
				<view @click="screen" class="tab-item">筛选</view>
				<view @click="selectedTab('近一个月')" class="tab-item" :class="tabSelected==='近一个月'? 'tab-selected':''">近一个月</view> -->
				<view @click="subTabClick('健康陕西')" class="tab-item" :class="classifySelected==='全部'? 'tab-selected':''">全部</view>
				<view @click="subTabClick('政策解读')" class="tab-item" :class="classifySelected==='政策解读'? 'tab-selected':''">政策解读</view>
				<view @click="subTabClick('健康陕西行动')" class="tab-item" :class="classifySelected==='健康陕西行动'? 'tab-selected':''">健康陕西行动</view>
			</view>
			<!-- <view class="right-btn">
				<picker mode="date">
					<view>自选</view>
				</picker>
				<image src="../../static/logo.png"></image>
			</view> -->
		</view>

		<view class="list-view">
			<view class="list-item" v-for="item in list" :key="item.uid" @click="goDetails(item)">
				<view class="left">
					<image :src="item.coverFileName"></image>
				</view>
				<view class="right">
					<view class="title">
						<!-- <image src="../../static/logo.png" class="play-icon"></image> -->
						<view class="titleName">{{item.titleName}}</view>
					</view>
					<view class="from-and_date">
						<text v-if="item.origin">{{item.origin}}|</text>
						{{item.releaseTime}}
					</view>
				</view>
			</view>
		</view>
		<view class="isOver" v-if="isOver">{{ overText }}</view>
		<!-- <uni-popup ref="popup" background-color="#fff">
			<view class="popup-content">
				<view class="tab-tit" style="color:#F69A23">
					政策解读
				</view>
				<view @click="subTabClick(item)" class="sub-tab-item"
					:class="classifyUid === item.uid ? 'sub-tab-item-selected' : ''" v-for="(item,index) in subTabs">
					{{item.classifyName}}
				</view>
				<view class="tab-tit" style="color:#F69A23">
					健康陕西行动
				</view>
				<view @click="subTabClick(item)" class="sub-tab-item"
					:class="classifyUid === item.uid ? 'sub-tab-item-selected' : ''" v-for="(item,index) in subTabs1"
					:key="item.uid">
					{{item.classifyName}}
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
	import * as topNewsList from '../../common/api/topNewsList.js'
	export default {
		data() {
			return {
				tabSelected: "最新",
				classifySelected:'全部',
				queryForm: {
					columnRecommendation: '是'
				},
				pageIndex: 1,
				pageSize: 10,
				total:0,
				isOver:false,
				overText:'---我是有底线的---',
				list: [],
				classify: "",
				classifyUid: "1d664d998e9a439ea5dda15e8f9562aa",
				subTabs: [{
					classifyName: "政策解读",
					uid: '9c4cc07f98a14e22b57a80456fef0ff4'
				}],
				subTabs1: [{
						"uid": "2a579e597ec343db90443b5a0b4630a0",
						"classifyName": "妇幼健康促进行动"
					},
					{
						"uid": "8210e44a7b944e06ab4d664f665d4ed2",
						"classifyName": "青少年健康促进行动"
					},
					{
						"uid": "b2dd4a8e28b1494696aecabbd0bb1970",
						"classifyName": "职业健康保护行动"
					},
					{
						"uid": "759c0922cb6a4062a3930b34584f4571",
						"classifyName": "老年健康促进行动"
					},
					{
						"uid": "efccf0fdbd1543a3827292746dd1a2e5",
						"classifyName": "重点慢性疾病防治行动"
					},
					{
						"uid": "b974ccf6b5f84ccfb8b15a15e176d311",
						"classifyName": "传染病防控行动"
					},
					{
						"uid": "9516b975c38e4ae8ab07a4dd2142d6c0",
						"classifyName": "地方病防控行动"
					},
					{
						"uid": "b8b7df0235864d1aade7d75e76541e76",
						"classifyName": "健康知识普及行动"
					},
					{
						"uid": "1b5e0663c39e41fa8fddc0c3820c3d1d",
						"classifyName": "合理膳食行动"
					},
					{
						"uid": "ae37c0f1aac241d7bdb6a20b7f6d3482",
						"classifyName": "全民健身行动"
					},
					{
						"uid": "e0361850cbc24a5a898400764c696833",
						"classifyName": "控烟限酒行动"
					},
					{
						"uid": "6b8a4aad69a54efb926754124372e5e5",
						"classifyName": "心理健康促进行动"
					},
					{
						"uid": "1d29fbbe8f7c4f1fa7a65f4e60211e66",
						"classifyName": "健康环境促进行动"
					},
					{
						"uid": "c975f60e0a894874b01112f25ccfa97a",
						"classifyName": "中医药健康促进行动"
					},
					{
						"uid": "fa7367e091ec4d64ab3a5e452bbb0d0e",
						"classifyName": "残疾预防健康行动"
					},
					{
						"uid": "568537cfa0754dcbaa964e47faf8b213",
						"classifyName": "健康细胞示范建设行动"
					},
					{
						"uid": "479d5c8260b64ab4a13fff03eef6bdd0",
						"classifyName": "健康保障完善行动"
					}
				],
				map: {
					text: 'classifyName',
					value: 'uid'
				},
			}
		},
		onLoad(e) {
			this.classify = e.classifyName
			this.getList()
			//this.queryTreeByCode()
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: '健康陕西列表'
			})
		},
		methods: {
			getList() {
				const param = {
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
					// classifyUid: this.classifyUid,
					...this.queryForm
				}
        param.classify = this.classifySelected;
        if(this.classifySelected == '全部'){
        	param.classify = '健康陕西';
        }
				/* if(this.classifySelected != '全部'){
					param.classify = this.classifySelected;
				}else{
					param.classifyUid = this.classifyUid;
				} */
				topNewsList.queryByPage(param).then(res => {
					// this.list = res.data.data.rows
					this.list = [...this.list,...res.data.data.rows]
					this.total = res.data.data.total;
					if (this.pageIndex * this.pageSize >= this.total) {
						this.isOver = true;
					}
				}).catch(error => {
					console.log(error)
				})
			},
			selectedTab(e) {
				this.tabSelected = e
				if (e === '推荐') {
					this.queryForm = {
						columnRecommendation: '是'
					}
				} else if (e === '最新') {
					this.queryForm = {}
				} else if (e === '近一个月') {
					this.queryForm = {}
				}
				this.getList()
			},
			goDetails(data) {
				uni.navigateTo({
					url: "/pages/details/details?uid=" + data.uid
				})
			},
			queryTreeByCode() {
				const param = {
					code: '2-JKSX',
				}
				topNewsList.queryTreeByCode(param).then(res => {
					// this.localdata = this.removeEmptyChildren(res.data.data)
					this.localdata = res.data.data
					//debugger
				}).catch(error => {
					console.log(error)
				})
			},
			removeEmptyChildren(node) {
				node.map(item => {
					if (!item.children || item.children.length === 0) {
						delete item.children
					} else {
						let res = item.children
						this.removeEmptyChildren(res)
					}
				})
				return node
			},
			screen() {
				this.$refs.popup.open('top')
			},
			subTabClick(item) {
				this.list = [];
				this.pageIndex = 1;
				// this.classifyUid = item.uid
				// this.$refs.popup.close()
				this.classifySelected = item;
				this.getList()
			}
		},
		// 下拉
		onReachBottom () {
			if (this.pageIndex * this.pageSize >= this.total) {
				this.isOver = true;
				return;
			} else {
				this.pageIndex++
				this.getList();
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: white;
		display: flex;
		flex-direction: column;
	}

	.top-tab-view {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-bottom:20rpx;
		background: #f5f5f5;
		position: fixed;

		.left-tab {
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			.tab-item {
				// width: 140rpx;
				padding:4rpx 10rpx;
				height: 48rpx;
				margin-top:20rpx;
				margin-left: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 24rpx;
				border-radius: 10rpx;
				background: rgba(48, 177, 141, 0.2);
				color: #30B18D;
			}

			.tab-selected {
				background: #27A280;
				color: #fff;
			}
		}

		.right-btn {
			display: flex;
			align-items: center;
			font-size: 24rpx;
			color: #CCCCCC;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 30rpx;
				margin-left: 10rpx;
			}
		}
	}
	
	.list-view {
		width: 100%;
		display: flex;
		flex-direction: column;
		padding: 110rpx 30rpx 0 30rpx;
		box-sizing: border-box;

		.list-item {
			width: 100%;
			display: flex;
			padding: 10rpx 0 30rpx 0;
			border-bottom: solid 1rpx #F5F7F7;

			.left {
				image {
					width: 180rpx;
					height: 135rpx;
					border-radius: 16rpx;
				}
			}

			.right {
				flex: 1;
				margin-left: 30rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.title {
					width: 480rpx;
					color: #666666;
					font-size: 30rpx;
					font-weight: 500;
					display: flex;
					align-items: center;

					.play-icon {
						width: 26rpx;
						height: 20rpx;
						margin-right: 20rpx;
					}

					.titleName {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}

				.from-and_date {
					color: #999999;
					font-size: 24rpx;
				}
			}
		}
	}

	.tab-tit {
		margin: 20rpx;
		font-size: 30rpx
	}

	.sub-tab-item {
		display: inline-block;
		line-height: 48rpx;
		height: 48rpx;
		color: #999999;
		margin: 23rpx 40rpx;
	}

	.sub-tab-item-selected {
		color: #333333;
		border-bottom: solid 4rpx #27A280;
	}
	.isOver{
		text-align: center;
		font-size: 12px;
		color:#bbb;
		height:60rpx;
		line-height:60rpx;
	}
</style>